package link.anyauto.fsmgr.biz.login;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;

import link.anyauto.fsmgr.FsmgrApp;
import link.anyauto.fsmgr.R;
import link.anyauto.fsmgr.base.BaseNames;
import link.anyauto.fsmgr.biz.main.ActMain;
import link.anyauto.fsmgr.biz.settings.ActSettings;

/**
 * Created by Administrator on 2016/7/16.
 */
public class LoginHandlers {

    public void accountChanged(CharSequence text) {
        login.setAcount(text.toString());
    }

    public void pwdChanged(CharSequence text) {
        login.setPwd(text.toString());
    }

    public void login(View view) {
        if(TextUtils.isEmpty(login.getAccount())) {
            accountE.setError(FsmgrApp.stringRes(R.string.login_err_account));
        }
        if(TextUtils.isEmpty(login.getPwd())) {
            pwdE.setError(FsmgrApp.stringRes(R.string.login_err_pwd));
        }
        if(TextUtils.isEmpty(login.getAccount()) || TextUtils.isEmpty(login.getPwd())) {
            return;
        }
        Intent in = new Intent(context, ActMain.class);
        in.putExtra(BaseNames.KEY_ACCOUNT, login.getAccount());
        context.startActivity(in);
    }

    public void settings(View view) {
        context.startActivity(new Intent(context, ActSettings.class));
    }

    Context context;
    LoginVM login;

    EditText accountE;
    EditText pwdE;
}
